package Test5;

import java.util.Objects;

public class Student  implements Comparable<Student> {
    private String name;
    private int physic;
    private int chemistry;

    public Student() {
    }

    public Student(String name, int physic, int chemistry) {
        this.name = name;
        this.physic = physic;
        this.chemistry = chemistry;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPhysic() {
        return physic;
    }

    public void setPhysic(int physic) {
        this.physic = physic;
    }

    public int getChemistry() {
        return chemistry;
    }

    public void setChemistry(int chemistry) {
        this.chemistry = chemistry;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", physic=" + physic +
                ", chemistry=" + chemistry +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return physic == student.physic && chemistry == student.chemistry && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, physic, chemistry);
    }

    @Override
    public int compareTo(Student o) {
        int thisTotal = this.physic + this.chemistry;
        int otherTotal = o.physic + o.chemistry;
        if (thisTotal != otherTotal) {
            return otherTotal - thisTotal; // 总分降序
        } else {
            return o.physic - this.physic; // 物理成绩降序
        }
    }
}
